
package cn.edu.scau.cmi.hombio.dao;

import cn.edu.scau.cmi.hombio.domain.MedicineTakeDetail;

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.skyway.spring.util.dao.AbstractJpaDao;

import org.springframework.dao.DataAccessException;

import org.springframework.stereotype.Repository;

import org.springframework.transaction.annotation.Transactional;

/**
 * DAO to manage MedicineTakeDetail entities.
 * 
 */
@Repository("MedicineTakeDetailDAO")

@Transactional
public class MedicineTakeDetailDAOImpl extends AbstractJpaDao<MedicineTakeDetail> implements MedicineTakeDetailDAO {

	/**
	 * Set of entity classes managed by this DAO.  Typically a DAO manages a single entity.
	 *
	 */
	private final static Set<Class<?>> dataTypes = new HashSet<Class<?>>(Arrays.asList(new Class<?>[] {
			MedicineTakeDetail.class }));

	/**
	 * EntityManager injected by Spring for persistence unit pig
	 *
	 */
	@PersistenceContext(unitName = "pig")
	private EntityManager entityManager;

	/**
	 * Instantiates a new MedicineTakeDetailDAOImpl
	 *
	 */
	public MedicineTakeDetailDAOImpl() {
		super();
	}

	/**
	 * Get the entity manager that manages persistence unit 
	 *
	 */
	public EntityManager getEntityManager() {
		return entityManager;
	}

	/**
	 * Returns the set of entity classes managed by this DAO.
	 *
	 */
	public Set<Class<?>> getTypes() {
		return dataTypes;
	}

	/**
	 * JPQL Query - findMedicineTakeDetailById
	 *
	 */
	@Transactional
	public MedicineTakeDetail findMedicineTakeDetailById(Integer id) throws DataAccessException {

		return findMedicineTakeDetailById(id, -1, -1);
	}

	/**
	 * JPQL Query - findMedicineTakeDetailById
	 *
	 */

	@Transactional
	public MedicineTakeDetail findMedicineTakeDetailById(Integer id, int startResult, int maxRows) throws DataAccessException {
		try {
			Query query = createNamedQuery("findMedicineTakeDetailById", startResult, maxRows, id);
			return (cn.edu.scau.cmi.hombio.domain.MedicineTakeDetail) query.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findMedicineTakeDetailByBoxTraceCodeContaining
	 *
	 */
	@Transactional
	public Set<MedicineTakeDetail> findMedicineTakeDetailByBoxTraceCodeContaining(String boxTraceCode) throws DataAccessException {

		return findMedicineTakeDetailByBoxTraceCodeContaining(boxTraceCode, -1, -1);
	}

	/**
	 * JPQL Query - findMedicineTakeDetailByBoxTraceCodeContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<MedicineTakeDetail> findMedicineTakeDetailByBoxTraceCodeContaining(String boxTraceCode, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findMedicineTakeDetailByBoxTraceCodeContaining", startResult, maxRows, boxTraceCode);
		return new LinkedHashSet<MedicineTakeDetail>(query.getResultList());
	}

	/**
	 * JPQL Query - findMedicineTakeDetailByBoxTraceCode
	 *
	 */
	@Transactional
	public Set<MedicineTakeDetail> findMedicineTakeDetailByBoxTraceCode(String boxTraceCode) throws DataAccessException {

		return findMedicineTakeDetailByBoxTraceCode(boxTraceCode, -1, -1);
	}

	/**
	 * JPQL Query - findMedicineTakeDetailByBoxTraceCode
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<MedicineTakeDetail> findMedicineTakeDetailByBoxTraceCode(String boxTraceCode, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findMedicineTakeDetailByBoxTraceCode", startResult, maxRows, boxTraceCode);
		return new LinkedHashSet<MedicineTakeDetail>(query.getResultList());
	}

	/**
	 * JPQL Query - findAllMedicineTakeDetails
	 *
	 */
	@Transactional
	public Set<MedicineTakeDetail> findAllMedicineTakeDetails() throws DataAccessException {

		return findAllMedicineTakeDetails(-1, -1);
	}

	/**
	 * JPQL Query - findAllMedicineTakeDetails
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<MedicineTakeDetail> findAllMedicineTakeDetails(int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAllMedicineTakeDetails", startResult, maxRows);
		return new LinkedHashSet<MedicineTakeDetail>(query.getResultList());
	}

	/**
	 * JPQL Query - findMedicineTakeDetailByTraceCodeContaining
	 *
	 */
	@Transactional
	public Set<MedicineTakeDetail> findMedicineTakeDetailByTraceCodeContaining(String traceCode) throws DataAccessException {

		return findMedicineTakeDetailByTraceCodeContaining(traceCode, -1, -1);
	}

	/**
	 * JPQL Query - findMedicineTakeDetailByTraceCodeContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<MedicineTakeDetail> findMedicineTakeDetailByTraceCodeContaining(String traceCode, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findMedicineTakeDetailByTraceCodeContaining", startResult, maxRows, traceCode);
		return new LinkedHashSet<MedicineTakeDetail>(query.getResultList());
	}

	/**
	 * JPQL Query - findMedicineTakeDetailByPrimaryKey
	 *
	 */
	@Transactional
	public MedicineTakeDetail findMedicineTakeDetailByPrimaryKey(Integer id) throws DataAccessException {

		return findMedicineTakeDetailByPrimaryKey(id, -1, -1);
	}

	/**
	 * JPQL Query - findMedicineTakeDetailByPrimaryKey
	 *
	 */

	@Transactional
	public MedicineTakeDetail findMedicineTakeDetailByPrimaryKey(Integer id, int startResult, int maxRows) throws DataAccessException {
		try {
			Query query = createNamedQuery("findMedicineTakeDetailByPrimaryKey", startResult, maxRows, id);
			return (cn.edu.scau.cmi.hombio.domain.MedicineTakeDetail) query.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findMedicineTakeDetailByTraceCode
	 *
	 */
	@Transactional
	public Set<MedicineTakeDetail> findMedicineTakeDetailByTraceCode(String traceCode) throws DataAccessException {

		return findMedicineTakeDetailByTraceCode(traceCode, -1, -1);
	}

	/**
	 * JPQL Query - findMedicineTakeDetailByTraceCode
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<MedicineTakeDetail> findMedicineTakeDetailByTraceCode(String traceCode, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findMedicineTakeDetailByTraceCode", startResult, maxRows, traceCode);
		return new LinkedHashSet<MedicineTakeDetail>(query.getResultList());
	}

	/**
	 * JPQL Query - findMedicineTakeDetailByIsBox
	 *
	 */
	@Transactional
	public Set<MedicineTakeDetail> findMedicineTakeDetailByIsBox(Integer isBox) throws DataAccessException {

		return findMedicineTakeDetailByIsBox(isBox, -1, -1);
	}

	/**
	 * JPQL Query - findMedicineTakeDetailByIsBox
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<MedicineTakeDetail> findMedicineTakeDetailByIsBox(Integer isBox, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findMedicineTakeDetailByIsBox", startResult, maxRows, isBox);
		return new LinkedHashSet<MedicineTakeDetail>(query.getResultList());
	}

	/**
	 * JPQL Query - findMedicineTakeDetailByCaseTraceCodeContaining
	 *
	 */
	@Transactional
	public Set<MedicineTakeDetail> findMedicineTakeDetailByCaseTraceCodeContaining(String caseTraceCode) throws DataAccessException {

		return findMedicineTakeDetailByCaseTraceCodeContaining(caseTraceCode, -1, -1);
	}

	/**
	 * JPQL Query - findMedicineTakeDetailByCaseTraceCodeContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<MedicineTakeDetail> findMedicineTakeDetailByCaseTraceCodeContaining(String caseTraceCode, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findMedicineTakeDetailByCaseTraceCodeContaining", startResult, maxRows, caseTraceCode);
		return new LinkedHashSet<MedicineTakeDetail>(query.getResultList());
	}

	/**
	 * JPQL Query - findMedicineTakeDetailByCaseTraceCode
	 *
	 */
	@Transactional
	public Set<MedicineTakeDetail> findMedicineTakeDetailByCaseTraceCode(String caseTraceCode) throws DataAccessException {

		return findMedicineTakeDetailByCaseTraceCode(caseTraceCode, -1, -1);
	}

	/**
	 * JPQL Query - findMedicineTakeDetailByCaseTraceCode
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<MedicineTakeDetail> findMedicineTakeDetailByCaseTraceCode(String caseTraceCode, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findMedicineTakeDetailByCaseTraceCode", startResult, maxRows, caseTraceCode);
		return new LinkedHashSet<MedicineTakeDetail>(query.getResultList());
	}

	/**
	 * Used to determine whether or not to merge the entity or persist the entity when calling Store
	 * @see store
	 * 
	 *
	 */
	public boolean canBeMerged(MedicineTakeDetail entity) {
		return true;
	}
}
